Skip to content

feat: Add one-shot attribute methods to FileSystemProtocol (Fixes #3648) - #3669

Open
wasim-builds wants to merge 4 commits into
apple:mainfrom
wasim-builds:feat/issue-3648-oneshot-attributes
Open

feat: Add one-shot attribute methods to FileSystemProtocol (Fixes #3648)#3669
wasim-builds wants to merge 4 commits into
apple:mainfrom
wasim-builds:feat/issue-3648-oneshot-attributes

Conversation

@wasim-builds

Copy link
Copy Markdown
Contributor

Hey @weissi! 👋

As discussed in #3648, I've added one-shot APIs to FileSystemProtocol to make it easier to set file attributes without having to explicitly open and manage a file handle.

Implementation Details:

  • Added setTimes, setLastAccessTime, and setLastDataModificationTime as default extension methods on FileSystemProtocol.
  • Under the hood, these methods automatically wrap withFileHandle(forReadingAt:) so it avoids the O_RDWR APFS decompression penalty you mentioned.
  • Applied the extensions to both NIOFS and _NIOFileSystem.

Let me know if you want any specific unit tests added or if this looks good to go! 🚀

@glbrntt glbrntt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This contains changes unrelated to the description; can you remove them? There are also no tests for the changes being made.

@wasim-builds
wasim-builds force-pushed the feat/issue-3648-oneshot-attributes branch from 829a6fb to 106e3cc Compare July 24, 2026 14:39
@wasim-builds

Copy link
Copy Markdown
Contributor Author

Thanks for the review! I've removed the unrelated commit and added test cases in FileSystemTests.swift to cover setTimes, setLastAccessTime, and setLastDataModificationTime. Let me know if everything looks good now! 🚀

@wasim-builds
wasim-builds force-pushed the feat/issue-3648-oneshot-attributes branch from 106e3cc to ba8aeea Compare July 27, 2026 07:04
@wasim-builds

Copy link
Copy Markdown
Contributor Author

Hey @glbrntt! I've rebased the branch to remove the stacked commits — this PR now only contains the FileSystem one-shot attribute methods (with tests). Ready for another look, thanks!

@wasim-builds

Copy link
Copy Markdown
Contributor Author

@glbrntt Following up on your review — Ive removed the unrelated changes and added tests covering all three one-shot attribute methods. Could you take another look when you get a chance?

@wasim-builds
wasim-builds force-pushed the feat/issue-3648-oneshot-attributes branch 2 times, most recently from 26e5b2f to ff6c083 Compare July 29, 2026 13:19
Comment thread Sources/NIOFS/FileSystemProtocol.swift Outdated
Comment on lines +697 to +725
public func setTimes(
forFileAt path: FilePath,
lastAccess: FileInfo.Timespec?,
lastDataModification: FileInfo.Timespec?
) async throws {
try await self.withFileHandle(forReadingAt: path) { handle in
try await handle.setTimes(lastAccess: lastAccess, lastDataModification: lastDataModification)
}
}

/// Sets the file's last access time to the given time.
///
/// - Parameters:
/// - path: The path of the file to modify.
/// - time: The time to which the file's last access time should be set.
public func setLastAccessTime(
forFileAt path: FilePath,
to time: FileInfo.Timespec
) async throws {
try await self.setTimes(forFileAt: path, lastAccess: time, lastDataModification: nil)
}

/// Sets the file's last data modification time to the given time.
///
/// - Parameters:
/// - path: The path of the file to modify.
/// - time: The time to which the file's last data modification time should be set.
public func setLastDataModificationTime(
forFileAt path: FilePath,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should all be using NIOFilePath instead of FilePath

@wasim-builds wasim-builds left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@glbrntt I've removed the unrelated changes and added tests covering all three one-shot attribute methods. The diff is now scoped to FileSystemProtocol.swift and FileSystemTests.swift only. Could you take another look?

wasim-builds added a commit to wasim-builds/swift-nio that referenced this pull request Aug 1, 2026
Address reviewer feedback on PR apple#3669: these methods should use NIOFilePath,
consistent with the rest of the FileSystemProtocol API.
@wasim-builds

Copy link
Copy Markdown
Contributor Author

Addressed: changed FilePath to NIOFilePath in all three methods, consistent with the rest of the FileSystemProtocol API. The branch is scoped to FileSystemProtocol.swift and FileSystemTests.swift only, with tests covering all three methods.

@wasim-builds

Copy link
Copy Markdown
Contributor Author

@glbrntt Friendly ping! The requested changes (NIOFilePath) were implemented and pushed. Could you please take another look?

@wasim-builds

Copy link
Copy Markdown
Contributor Author

Hi @glbrntt, I've addressed the requested changes: removed unrelated commits and added tests covering all three one-shot attribute methods. The current diff is scoped to FileSystemProtocol.swift and FileSystemTests.swift only. Could you please take another look when you have time? Thanks!

wasim-builds added a commit to wasim-builds/swift-nio that referenced this pull request Aug 12, 2026
Address reviewer feedback on PR apple#3669: these methods should use NIOFilePath,
consistent with the rest of the FileSystemProtocol API.
@wasim-builds
wasim-builds force-pushed the feat/issue-3648-oneshot-attributes branch 3 times, most recently from df8d936 to 6b35869 Compare August 17, 2026 06:02
@wasim-builds
wasim-builds force-pushed the feat/issue-3648-oneshot-attributes branch from 6b35869 to 9a000d9 Compare August 27, 2026 19:13
@wasim-builds

Copy link
Copy Markdown
Contributor Author

The requested changes have been addressed. Let me know if anything else is needed!

@wasim-builds
wasim-builds force-pushed the feat/issue-3648-oneshot-attributes branch from 9a000d9 to 32c6c7c Compare August 30, 2026 16:29
@wasim-builds

Copy link
Copy Markdown
Contributor Author

@glbrntt The requested changes to use NIOFilePath instead of FilePath have been applied and force-pushed. PTAL!

Co-authored-by: glbrntt <github@glbrntt.co.uk>
@wasim-builds

Copy link
Copy Markdown
Contributor Author

Hey glbrntt, I've updated all the one-shot attribute methods to use NIOFilePath instead of FilePath. Thanks for catching that!

@wasim-builds

Copy link
Copy Markdown
Contributor Author

Hi @glbrntt, friendly re-review request! The requested changes are already applied in the latest push:

  • All one-shot attribute methods use NIOFilePath consistently with the rest of FileSystemProtocol.
  • The diff is scoped only to FileSystemProtocol.swift and FileSystemTests.swift, with tests covering setTimes, setLastAccessTime, and setLastDataModificationTime.
    No unrelated changes remain. Could you take another look when you get a chance? Thanks!

@wasim-builds

Copy link
Copy Markdown
Contributor Author

I've removed the duplicated tests and made sure the implementation is clean and effective. Ready for review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants